<template>
<div>
  <el-breadcrumb separator-class="el-icon-arrow-right" style="font-size: 16px;">
    <el-breadcrumb-item :to="{ path: '/admin/adminPage/AdminIndex' }">
      <i class="el-icon-s-promotion"></i> 后台管理
    </el-breadcrumb-item>
    <el-breadcrumb-item>酒店投诉管理</el-breadcrumb-item>
  </el-breadcrumb>
  <el-divider></el-divider>
  <el-table :data="tableData" border style="width: 100%">
    <el-table-column prop="id" label="投诉Id" width="80px" align="center"></el-table-column>
    <el-table-column prop="hotelName" label="酒店名字" width="200px"  align="center"
                     :show-overflow-tooltip="true">
    </el-table-column>
    <el-table-column prop="hotelId" label="酒店Id" width="80px" align="center">
    </el-table-column>
    <el-table-column prop="username" label="用户名" width="120px" align="center"
                     :show-overflow-tooltip="true">
    </el-table-column>>
    <el-table-column prop="userId" label="用户Id" width="80px" align="center">
    </el-table-column>
    <el-table-column prop="complainText" label="投诉内容" width="200px" align="center"
                     :show-overflow-tooltip="true">
    </el-table-column>
    <el-table-column prop="state" label="审核状态" width="100px" align="center"
                     :show-overflow-tooltip="true">
    </el-table-column>
    <el-table-column prop="created" label="投诉时间" width="100px" align="center"
                     :show-overflow-tooltip="true">
    </el-table-column>
    <el-table-column prop="feedbackContent" width="250px" label="反馈内容" align="center"
                     :show-overflow-tooltip="true">
    </el-table-column>
    <el-table-column label="审核反馈" align="center"
                     :show-overflow-tooltip="true">
      <template  slot-scope="scope">
        <el-button :disabled="scope.row.state=='已审核'" v-if="scope.row.id!=complainingId" @click="startFeedback(scope.row)" type="primary">开始审核</el-button>
        <span v-if="scope.row.id==complainingId">
        <el-button @click="stopFeedback()">暂停审核</el-button>
        <el-button type="primary" @click="finishFeedback()">完成审核</el-button>
        </span>
      </template>
    </el-table-column>
    <el-table-column label="操作" width="80px" align="center">
      <template slot-scope="scope">
        <el-button :disabled="scope.row.state=='审核中'" type="danger" icon="el-icon-delete" circle size="mini"
                   @click="openDeleteConfirm(scope.row)">
        </el-button>
      </template>
    </el-table-column>
  </el-table>
  <el-drawer
      :modal="false"
      title="反馈内容"
       class="drawer-style"
      size="100%"
      :show-close="false"
      :visible.sync="drawer"
      :wrapperClosable="false"
      :direction="direction"
      >
    <el-input v-model="result" style="width: 450px" type="textarea"></el-input>
  </el-drawer>

</div>
</template>

<script>
export default {
  data(){
    return{
      tableData:[],
      feedbackState:true,
      drawer: false,
      direction: 'rtl',
      complainingId:'',
      currentItem:'',
      result:''

    }
  },
  methods:{
    finishFeedback(){
      let url = 'http://localhost:9580/hotelComplains/admin/'+
          this.currentItem.id+'/updateHotelComplainingById/'+this.result;
      console.log('url'+url);

      this.axios
          .create({'headers':{'Authorization':localStorage.getItem('aJwt')}})
          .post(url).then((response) =>{
        let responseBody=response.data;
        if (responseBody.state==20000){
          this.dialogFormVisible=false;
          this.$message({
            message: '反馈审核信息成功！',
            type: 'success'
          });
          this.drawer=false;
          this.loadHotelComplainingList();
          this.complainingId='';
          this.result='';
        }else if (responseBody.state == 40400) {
          this.$alert(responseBody.message, '警告', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadHotelComplainingList();
            }
          });
        } else {
          this.$message.error(responseBody.message);
        }
      })
    },
    stopFeedback(){
      this.complainingId='';
      this.drawer=false;
      this.loadHotelComplainingList();
    },
    startFeedback(item){
      this.complainingId=item.id;
      this.currentItem=item;
      this.drawer=true;
      this.loadHotelComplainingList();
    },
    openDeleteConfirm(item) {
      let message = '此操作将永久删除【' + item.username + '】对酒店【'+item.hotelName+'】的投诉，是否继续？';
      this.$confirm(message, '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.handleDelete(item);
      }).catch(() => {
      });
    },
    handleDelete(item) {
      let url = 'http://localhost:9580/hotelComplains/admin/'+item.id+'/deleteAdminHotelComplainingById';
      console.log('url = ' + url);
      this.axios
          .create({'headers': {'Authorization': localStorage.getItem('aJwt')}})
          .post(url).then((response) => {
        let responseBody = response.data;
        if (responseBody.state == 20000) {
          this.$message({
            message: '删除用户投诉数据成功！',
            type: 'success'
          });
          this.loadHotelComplainingList();
        } else if (responseBody.state == 40400) {
          this.$alert(responseBody.message, '警告', {
            confirmButtonText: '确定',
            callback: action => {
              this.loadHotelComplainingList();
            }
          });
        } else {
          this.$message.error(responseBody.message);
        }
      });
    },
    loadHotelComplainingList(){
      let url = 'http://localhost:9580/hotelComplains/admin/getAdminHotelComplaining';
      console.log("url"+url);
      this.axios
          .create({'headers':{'Authorization':localStorage.getItem('aJwt')}})
          .get(url).then((response) =>{
        let responseBody=response.data;
        this.tableData=responseBody.data;
        for (let item of this.tableData) {
          item.created=item.created.replace(/[T]+/g,' ');
          if (item.feedbackContent==null){
            item.feedbackContent='暂无数据';
          }
        }
        console.log(this.tableData);
      })
    }
  },
  mounted() {
    this.loadHotelComplainingList();
  }
}
</script>

<style scoped>
.drawer-style{
  text-align: center;
  border: 1px solid black;
  height: 150px;
  width: 600px;
  float: right;
  left: 1300px;
  border-radius: 20px;
}
</style>